﻿
var getRandomColor1=function(){
		var colorStr = Math.floor(Math.random()*0xFFFFFF).toString(16).toUpperCase();
		return "#"+"000000".substring(0,6-colorStr)+colorStr;
}

/***
 * 获取颜色码数组,数组长度为10
 */
var getColorsArray = function(i) {
	var colorsArr=['#FFB6C1','#DA70D6','#7B68EE','#0000FF','#1E90FF','#000000','#D6Ab3A','#310000','#A4B0C0','#75B0C0','#427EC0'];
	if (!colorsArr[i]) {
		return colorsArr[0];
	} else {
		return colorsArr[i];
	}
}

/**
 * 绘制聚类后的聚类个数饼状图
 */
var renderClusterPie = function(ele, dataset) {
	var width = 200,height = 200;
	//var dataset = [["聚类1",50], ["聚类2",50], ["聚类3",50]];
	//创建饼状图布局及值访问器
    var pie = d3.layout.pie().value(function(d){return d[1];});
    
    //dataset为初始数据，piedata为转换后的数据
    var piedata = pie(dataset);
    
    //定义外半径和内半径
    var outerRadius = width / 3.4;
    var innerRadius = 0;
    
    //创建弧生成器
    var arc = d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius);
    
    //var color = d3.scale.category20();
    var svg = d3.select(ele).append("svg").attr("width",width+150).attr("height",height);
    
    //添加弧的路径元素
    var arcs = svg.selectAll("g").data(piedata).enter().append("g").attr("transform","translate("+width+","+(height/2)+")");
    arcs.append("path")
    .attr("fill",function(d,i){
    	return getColorsArray(i);
    })
    .attr("d",function(d){
    	return arc(d);
    });
    
    //添加弧内的文字元素
    arcs.append("text").attr("transform",function(d){
    	var x = arc.centroid(d)[0]*1.4;
    	var y = arc.centroid(d)[1]*1.4;
    	return "translate("+x+","+y+")";
    }).attr("text-anchor","middle").text(function(d){
    	return "";
    });
    
    //添加连接弧外文字的直线元素
    arcs.append("line").attr("stroke","black").attr("x1",function(d){return arc.centroid(d)[0]*2;})
    				   .attr("stroke","black").attr("y1",function(d){return arc.centroid(d)[1]*2;})
    				   .attr("stroke","black").attr("x2",function(d){return arc.centroid(d)[0]*2.2;})
    				   .attr("stroke","black").attr("y2",function(d){return arc.centroid(d)[1]*2.2;});
    //添加弧外的文字元素
    arcs.append("text").attr("transform",function(d){
    	var x = arc.centroid(d)[0]*2.5;
    	var y = arc.centroid(d)[1]*2.5;
    	return "translate("+x+","+y+")";
    }).attr("text-anchor","middle").text(function(d){
    	return d.data[0]+"-"+d.data[1];
    });
}
/**
 * 绘制没有字符列参与计算的散点图
 */
var drawNumScatterChartNum1=function(width,height,pointArr,labelColors,ele,centerTable,classNum,xyTitles){
	var padding = { top: 50 , right: 30 , bottom: 50, left: 60};
	var scatterWidth = width - padding.left - padding.right,
	scatterHeight = height - padding.top - padding.bottom-50;
	var svg = d3.select(ele).append("svg")
	.attr("width",width)
	.attr("height",height);
	xyTitles = xyTitles || {};
	var xAxisTitle = xyTitles["xTitle"] || TempoUtils.locale("mine.xAxis");
	var yAxisTitle = xyTitles["yTitle"] || TempoUtils.locale("mine.yAxis");
 	var xTitle = svg.append("text").text(xAxisTitle).attr("text-anchor", "middle")
	.attr("x", (padding.left + (width - padding.left) / 2) + "px")
	.attr("y", (height-padding.bottom)-40 + "px")
	.attr("dy", "2em")
	.attr("class", "gl_axis_title");
	//Y轴字段信息过长时  显示不全 截取15后省略...
	yAxisTitle = yAxisTitle.length > 15 ? yAxisTitle.substring(0,15) + "..." : yAxisTitle;
	var yTitle = svg.append("text").text(yAxisTitle).attr("text-anchor", "middle")
	.attr("y", padding.right + "px")
	.attr("dy", "-1em")
	.attr("x", -(padding.bottom + (height - padding.bottom) / 2) + 50 + "px")
	.attr("transform", "rotate(-90)")
	.attr("class", "gl_axis_title");
	var xScale = d3.scale.linear()
	   .domain([d3.min(pointArr,function(d){
		   return parseFloat(d[0]);
	   }),d3.max(pointArr,function(d){
		   return parseFloat(d[0]);
	   })])
	   .range([0,scatterWidth]);
	var yScale = d3.scale.linear()
		.domain([d3.min(pointArr,function(d){
			   return parseFloat(d[1]);
		   }),d3.max(pointArr,function(d){
		   return parseFloat(d[1]);
	   })])
	   .range([scatterHeight,0]);

	var cirlce = svg.selectAll(".regPointCircle")
		.data(pointArr)
		.enter()
		.append("circle")
		.attr("fill",function(d){
			return labelColors[d[2]];
		})
		.attr("cx",function(d){
			return padding.left + xScale(d[0])
		})
		.attr("cy",function(d){
			return scatterHeight + padding.top - yScale(d[1]);
		})
		.attr("r","5");
	var xAxis = d3.svg.axis().scale(xScale).tickFormat(function(value){
		if (value < 1000) {
			return value;
		} else if (value < 1000000) {
			return (value / 1000) + "K";
		} else if (value < 1000000000){
			return (value / 1000000) + "M";
		} else {
			return (value / 1000000000) + "B";
		}
	}).orient("bottom");
	//yScale.range([scatterHeight,0]);
	var yAxis = d3.svg.axis().scale(yScale).tickFormat(function(value){
		if (value < 1000) {
			return TempoMineUtils.dataD3Treating(value);
		} else if (value < 1000000) {
			return (value / 1000) + "K";
		} else if (value < 1000000000){
			return (value / 1000000) + "M";
		} else {
			return (value / 1000000000) + "B";
		}
	}).orient("left");
	svg.append("g").attr("class","axis")
				   .attr("transform","translate("+padding.left+","+(scatterHeight + padding.top)+")")
				   .call(xAxis);
	svg.append("g").attr("class","axis")
	   .attr("transform","translate("+padding.left+","+ padding.top +")")
	   .call(yAxis);
	addLegend(svg,labelColors,height,centerTable,classNum);
}

/**
 * 绘制单个字符列参与计算的散点图
 */
var drawNumScatterChartOneNorm1=function(width,height,pointArr,labelColors,ele,centerTable,classNum,xyTitles){
	var padding = { top: 50 , right: 30 , bottom: 50, left: 120};
	// 留出50的宽度显示图例
	var scatterWidth = width - padding.left - padding.right,
	scatterHeight = height - padding.top - padding.bottom-50;
	var svg = d3.select(ele).append("svg")
	.attr("width",width)
	.attr("height",height);
	xyTitles = xyTitles || {};
	var yAxisTitle = xyTitles["xTitle"] || TempoUtils.locale("mine.yAxis");
	var xAxisTitle = xyTitles["yTitle"] || TempoUtils.locale("mine.xAxis");
 	var xTitle = svg.append("text").text(xAxisTitle).attr("text-anchor", "middle")
	.attr("x", (padding.left + (width - padding.left) / 2) + "px")
	.attr("y", (height-padding.bottom)-40 + "px")
	.attr("dy", "2em")
	.attr("class", "gl_axis_title");
	//Y轴字段信息过长时  显示不全 截取15后省略...
	yAxisTitle = yAxisTitle.length > 15 ? yAxisTitle.substring(0,15) + "..." : yAxisTitle;
	var yTitle = svg.append("text").text(yAxisTitle).attr("text-anchor", "middle")
	.attr("y", padding.right + "px")
	.attr("dy", "-1em")
	.attr("x", -(padding.bottom + (height - padding.bottom) / 2) + 50 + "px")
	.attr("transform", "rotate(-90)")
	.attr("class", "gl_axis_title");
	
	var xScale = d3.scale.linear()
	   .domain([d3.min(pointArr,function(d){
		   return parseFloat(d[1]);
	   }),d3.max(pointArr,function(d){
		   return parseFloat(d[1]);
	   })])
	   .range([0,scatterWidth]);
	
	// 最多显示20个 单字符类型传递1 用于获取构造正确的y轴信息
	var res = filterPointer(pointArr,"1");
	pointArr = res.pointArr;
	// 计算半径的比例，若maxRadius为空，则比例默认为0.08
	
	var yDataSets=res.key;
	var yScale = d3.scale.ordinal()
	.domain(yDataSets)
	.rangeRoundBands([0, scatterHeight],1);
	var cirlce = svg.selectAll(".regPointCircle")
		.data(pointArr)
		.enter()
		.append("circle")
		.attr("fill",function(d){
			return labelColors[d[2]];
		})
		.attr("cx",function(d){
			return isNaN(xScale(d[1])) ? padding.left:padding.left + xScale(d[1]);
		})
		.attr("cy",function(d){
			return scatterHeight + padding.top - yScale(d[0]);
		})
		.attr("r",function(d){
			return getRadius(res.maxRadius,d[3]);
		});
	
	var xAxis = d3.svg.axis().scale(xScale).orient("bottom");
	//modify 2022-12-02 hanji 处理内网66630
	var yAxis = d3.svg.axis().scale(yScale).tickFormat(function(value){
		return TempoMineUtils.dataD3Treating(value);
	}).orient("left");
	svg.append("g").attr("class","axisMin")
				   .attr("transform","translate("+padding.left+","+(scatterHeight + padding.top)+")")
				   .call(xAxis);
	var leftEle = svg.append("g").attr("class","axisMin")
	   .attr("transform","translate("+padding.left+","+ padding.top +")")
	   .call(yAxis);

	// 标签tooltip
	leftEle.selectAll("g").append("title")
				.data(yDataSets)
				.text(function(d,i){
					return d;
				});
	leftEle.selectAll("text").text(function(name){
		if (name.length > 10){
			name = name.substring(0,8)+"...";
		}
		return name;
	})
	addLegend(svg,labelColors,height,centerTable,classNum);
}

/**
 * 绘制多个字符列参与计算的散点图
 */
var drawNumScatterChartOverNorm1=function(width,height,pointArr,labelColors,ele,centerTable,classNum,xyTitles){
	var padding = { top: 50 , right: 30 , bottom: 50, left: 120};
	var scatterWidth = width - padding.left - padding.right,
	scatterHeight = height - padding.top - padding.bottom-50;
	var svg = d3.select(ele).append("svg")
	.attr("width",width)
	.attr("height",height);
	xyTitles = xyTitles || {};
	var xAxisTitle = xyTitles["xTitle"] || TempoUtils.locale("mine.xAxis");
	var yAxisTitle = xyTitles["yTitle"] || TempoUtils.locale("mine.yAxis");
 	var xTitle = svg.append("text").text(xAxisTitle).attr("text-anchor", "middle")
	.attr("x", (padding.left + (width - padding.left) / 2) + "px")
	.attr("y", (height-padding.bottom)-40 + "px")
	.attr("dy", "2em")
	.attr("class", "gl_axis_title");
	//Y轴字段信息过长时  显示不全 截取15后省略...
	yAxisTitle = yAxisTitle.length > 15 ? yAxisTitle.substring(0,15) + "..." : yAxisTitle;
	var yTitle = svg.append("text").text(yAxisTitle).attr("text-anchor", "middle")
	.attr("y", padding.right + "px")
	.attr("dy", "-1em")
	.attr("x", -(padding.bottom + (height - padding.bottom) / 2) + 50 + "px")
	.attr("transform", "rotate(-90)")
	.attr("class", "gl_axis_title");
	
	var xDataSets=[];
	for (var i=0;i<pointArr.length;i++){
		xDataSets.push(pointArr[i][0]);
	}
	var xScale = d3.scale.ordinal()
	.domain(xDataSets)
	.rangeRoundBands([0, scatterWidth],1);
	// 最多显示20个 多字符类型传递2 用于获取构造正确的y轴信息
	var res = filterPointer(pointArr,"2");
	pointArr = res.pointArr;
	var yDataSets=res.key;
	
	var yScale = d3.scale.ordinal()
	.domain(yDataSets)
	.rangeRoundBands([0, scatterHeight],1);
	var cirlce = svg.selectAll(".regPointCircle")
		.data(pointArr)
		.enter()
		.append("circle")
		.attr("fill",function(d){
			return labelColors[d[2]];
		})
		.attr("cx",function(d){
			return isNaN(xScale(d[0])) ? padding.left:padding.left + xScale(d[0]);
		})
		.attr("cy",function(d){
			return isNaN(yScale(d[1])) ? scatterHeight + padding.top : scatterHeight + padding.top - yScale(d[1]);
		})
		.attr("r",function(d){
			return getRadius(res.maxRadius,d[3]);
		});
	
	var xAxis = d3.svg.axis().scale(xScale).orient("bottom");
    //modify 2022-12-02 hanji 处理内网66630
	var yAxis = d3.svg.axis().scale(yScale).tickFormat(function(value){
		return TempoMineUtils.dataD3Treating(value);
	}).orient("left");
	svg.append("g").attr("class","axis")
				   .attr("transform","translate("+padding.left+","+(scatterHeight + padding.top)+")")
				   .call(xAxis);
	var leftEle = svg.append("g").attr("class","axis")
	   .attr("transform","translate("+padding.left+","+ padding.top +")")
	   .call(yAxis);
	addLegend(svg,labelColors,height,centerTable,classNum);

	// 标签tooltip
	leftEle.selectAll("g").append("title")
				.data(yDataSets)
				.text(function(d,i){
					return d;
				});
	leftEle.selectAll("text").text(function(name){
		if (name.length > 10){
			name = name.substring(0,8)+"...";
		}
		return name;
	})
}
/**
 * 加载最优算法模型基本信息
 */
var bestTable = function(info,parentEle){
	var bestModelName = info.bestModelName;
	var bestParams = info.params;
	var bestParamsDiv = parentEle;
	var lable = "<lable>" + TempoUtils.locale("mine.zuiyousuanfawei")
			+ TempoUtils.locale("autoclustering." + bestModelName)
			+ TempoUtils.locale("mine.zuiyoucanshu") + "</lable>";
	$("" + lable + "").appendTo(bestParamsDiv);
	var thead = $('<thead/>').appendTo(bestParamsDiv);
	var headTr = "<table>";
	for ( var key in bestParams) {
		var bestValue = "";
		if (key == "penaltyParam") {
			if (bestParams[key] == "1.0") {
				bestValue = "L1";
			} else if (bestParams[key] == "0.0") {
				bestValue = "L2";
			} else if (bestParams[key] == "l12") {
				bestValue = "L1+L2";
			}
		} else {
			bestValue = bestParams[key];
		}
		console.log(key+bestParams[key]);
		
		
		if(key=="initializationMethod"){
			
			if(bestValue=="k-means||"){
				bestValue = "Kmeans++";
			}
		}
		
		if(bestModelName == "twostep" && key == "distanceMode"){
			bestValue = TempoUtils.locale("twostep."+ bestValue)
		}else if(bestModelName == "kmeans" && key == "distanceMode"){
			bestValue = TempoUtils.locale("kmeans."+ bestValue)
		}
		headTr += "<tr><td>"
				+ TempoUtils.locale("autoclustering." + key)
				+ "</td><td>" + bestValue + "</td></tr>";
	}
	headTr += "</table>";
	$(headTr).appendTo(thead);
}
/**
 * 聚类分类下节点洞察统称
 * @param info
 * @param parentEle
 * @param auto
 */
window.showClusterResPic1 = function(info,parentEle,auto) {
		var featuresCol = info.featuresCol;
		var centerTable = info.centerTable;
		var distanceTable = info.distanceTable;
		//聚类全部节点空数据集洞察展示
		if(distanceTable.length < 1){
			TempoMineInsightUtils.showNullModelInsight(parentEle);
		}else{
			var btnName="#"+info.nodeConfigId+"_btn_download";
			var nodeConfigId = info.nodeConfigId;
			var producerNodeTypeId = info.producerNodeTypeId;
			if(nodeConfigId=="" && producerNodeTypeId=="em" ){
				var nodeName=TempoUtils.locale("autoclustering." +producerNodeTypeId)+"-";
			}else{
				var nodeName=TempoUtils.locale("autoclustering." +info.nodeConfigId)+"-";
			}
			//修改自动聚类当中下载文件名为undefined的问题
			if(info && info.nodeConfigId != undefined && info.nodeConfigId.length==0){
				nodeName=TempoUtils.locale("autoclustering." +info.producerNodeTypeId)+"-";
			}
			if(info.nodeConfigId=="autoclustering"){
				nodeName=TempoUtils.locale("autoclustering." +info.bestModelName)+"-";
			}

			if(auto == "auto"){
				bestTable(info,parentEle);
			}
			var clustervarImportanceDiv = $('<div/>').appendTo(parentEle);
			var var2Importance = info.var2Importance;

			if (var2Importance) {
				clustervarImportanceDiv.append("<div/>");
				clustervarImportanceDiv.css({"margin-top":"10px"});
				TempoMineChartUtils.drawVarImportanceChart(var2Importance,clustervarImportanceDiv.children()[0],1000,400);
			} else {
				clustervarImportanceDiv.hide();
			}
			var tab = $('<div/>',{'class':'tempo-mine-viewing-options'}).appendTo(parentEle)
				.append($("<span class='tempo-mine-viewing-result-style' id='tempo-mine-result-view-result-table-cluster-pic-option'>"+TempoUtils.locale("mine.cluster_graphic")+"</span>"))
				.append($("<span class='tempo-mine-viewing-result-style' id='tempo-mine-result-viewing-cluster-center'>"+TempoUtils.locale("mine.cluster_center_table")+"</span>"))
				.append($("<span class='tempo-mine-viewing-result-style' id='tempo-mine-result-viewing-cluster-center-distance'>"+TempoUtils.locale("mine.cluster_center_distance_table")+"</span>"));

			var clusterTableInfo = $('<div/>',{
				'class':'tempo-mine-result-view-result-table-cluster-table-info'
			}).appendTo(parentEle).css("overflow","initial");


			tab.find('#tempo-mine-result-view-result-table-cluster-table-option').unbind('click').bind('click',function(){
				if (!$(this).hasClass('tempo-mine-viewing-result-style-sel')) {
					$(this).addClass('tempo-mine-viewing-result-style-sel');
				}
				$(this).siblings().removeClass('tempo-mine-viewing-result-style-sel');
				clusterTableInfo.html('');
				//clusterFeatureDiv.html("");
				var clusterModelInfo = $('<div/>',{
					'class':'tempo-mine-result-view-result-table-cluster-model-info'
				}).appendTo(clusterTableInfo);

				var clusterTableDetailInfo = $('<div/>',{
					'class':'tempo-mine-result-view-result-table-cluster-table-detail-info'
				}).appendTo(clusterTableInfo);

				$('<p/>',{
					text:TempoUtils.locale('mine.clustermodel')
				}).appendTo(clusterModelInfo);
				var classNum = info.classNum;
				for (var j=0;j<classNum.length;j++) {
					var clusterClassDesc = TempoUtils.locale('mine.clusterclassdesc').replace('num',(j+1)+"").replace('count',classNum[j]);
					$('<p/>',{text:clusterClassDesc}).appendTo(clusterModelInfo);
				}
				createResTable(info,featuresCol,clusterTableDetailInfo);
			});



			tab.find('#tempo-mine-result-view-result-table-cluster-pic-option').unbind('click').bind('click',function(){
				if($(btnName)){
					$(btnName).remove();
				}
				if (!$(this).hasClass('tempo-mine-viewing-result-style-sel')) {
					$(this).addClass('tempo-mine-viewing-result-style-sel');
				}
				$(this).siblings().removeClass('tempo-mine-viewing-result-style-sel');
				clusterTableInfo.html('');
				//clusterFeatureDiv.html("");
				var clusterPicDataList = info.clusterPicDataList;
				var clusterPicType = info.clusterPicType;
				var classNum = info.classNum;
				var xyTitles = info.xyTitles;

				var dataset = [];
				for (var i = 0; i < classNum.length; i++) {
					var item = [];
					item.push(TempoUtils.locale("mine.cluster") + (i+1));
					item.push(classNum[i]);
					dataset.push(item);
				}
				// 画圆饼图
				renderClusterPie(clusterTableInfo.get(0), dataset);
				if (clusterPicType == 'lessTwoCols') {
					clusterTableInfo.append('<p>'+TempoUtils.locale('mine.clusterPicBlack')+'</p>');
				} else {
					var pointArr = [],width = clusterTableInfo.width()-50,
						height=350;
					var labelColors=[];
					var clusterNum = clusterPicDataList.length;
					for (var i=0;i<clusterPicDataList.length;i++) {
						if (clusterPicType == 'noNormCols') {
							var clusterPicData = clusterPicDataList[i];
							var x=clusterPicData.split(";")[0].split(',')[0];
							var y=clusterPicData.split(";")[0].split(',')[1];
							var label=parseInt(clusterPicData.split(";")[1]);
							if (!labelColors[label]) {
								labelColors[label]=getColorsArray(label);
							}
							pointArr.push([x,y,label]);
						} else if (clusterPicType == 'oneNormCols') {
							var clusterPicData = clusterPicDataList[i];
							var x=clusterPicData.split(";")[0].split(',')[0];
							var y=clusterPicData.split(";")[0].split(',')[1];
							var label=parseInt(clusterPicData.split(";")[1]);
							var num=parseInt(clusterPicData.split(";")[2]);
							if (!labelColors[label]) {
								labelColors[label]=getColorsArray(label);
							}
							pointArr.push([x,y,label,num]);
						} else if (clusterPicType == 'overTwoNormCols') {
							var clusterPicData = clusterPicDataList[i];
							var x=clusterPicData.split(";")[0].split(',')[0];
							var y=clusterPicData.split(";")[0].split(',')[1];
							var label=parseInt(clusterPicData.split(";")[1]);
							var num=parseInt(clusterPicData.split(";")[2]);
							if (!labelColors[label]) {
								labelColors[label]=getColorsArray(label);
							}
							pointArr.push([x,y,label,num]);
						}
					}
					// 加一条提示语句
					var tipDiv = $("<div>").appendTo(clusterTableInfo.get(0));
					$("<div style='color: blue;padding-right:30px; float: right'><label>"+TempoUtils.locale("mine.tophelptip")+"</label></div>").appendTo(tipDiv);
					if (clusterPicType == 'noNormCols') {
						drawNumScatterChartNum1(width,height,pointArr,labelColors,clusterTableInfo.get(0),centerTable,classNum,xyTitles);
					} else if (clusterPicType == 'oneNormCols') {
						drawNumScatterChartOneNorm1(width,height,pointArr,labelColors,clusterTableInfo.get(0),centerTable,classNum,xyTitles);
					} else if (clusterPicType == 'overTwoNormCols') {
						drawNumScatterChartOverNorm1(width,height,pointArr,labelColors,clusterTableInfo.get(0),centerTable,classNum,xyTitles);
					}
				}
			});

			var getExcelData = function() {
				//创建下载数据数组
				var clusterCenterTable=[];
				var row=[];
				for (var i=0;i<centerTable.length;i++) {
					//避免js赋值影响
					row=$.extend(true,[],centerTable[i]);
					if (i == 0) {
						row.unshift(TempoUtils.locale("mine.mine_fields"));
						row.push(TempoUtils.locale("mine.cluster_num"));
					}else{
						row.unshift(TempoUtils.locale("mine.cluster_center").replace("replace_this",i));
						row.push(info.classNum[i-1])
					}
					clusterCenterTable.push(row);
				}
				return clusterCenterTable;
			}
			var excelData = getExcelData();

			tab.find('#tempo-mine-result-viewing-cluster-center').unbind('click').bind('click',function(){
				if (!$(this).hasClass('tempo-mine-viewing-result-style-sel')) {
					$(this).addClass('tempo-mine-viewing-result-style-sel');
				}
				$(this).siblings().removeClass('tempo-mine-viewing-result-style-sel');
				clusterTableInfo.html("");
				var correlationCoefDiv=$("<div class='mine-model-view-title' style='padding-bottom:10px;'></div>").appendTo(clusterTableInfo);
				$("<label style='font-size: 14px;font-weight: bold;'>"+TempoUtils.locale("mine.cluster_center_table")+"</label>").appendTo(correlationCoefDiv);

				TempoMineUtils.getDownLoadBtn().unbind("click").bind("click",function(){

					var tableData = {
						"matrixdatas":JSON.stringify(excelData),
						"fileName":nodeName + TempoUtils.locale("mine.cluster_center_table")+".xls"
					};
					TempoUtils.downLoadFile({
						url: contextPath + "/api/ai/mineresource/downloadTables",
						data :tableData
					});

				}).appendTo(correlationCoefDiv);
				var centerTa = $('<table class="tempo-mine-insight-table"></table>').appendTo(clusterTableInfo);
				var thead='<thead><tr>';
				var tbody='<tbody>';
				var classNum = info.classNum;
				var colNums = 0;
				if (centerTable && centerTable.length > 0 && centerTable[0] && centerTable[0].length > 0) {
					colNums = centerTable[0].length;
				}
				if (colNums <= 16) {
					for (var i=0;i<centerTable.length;i++) {
						var row = centerTable[i];
						if (i == 0) {
							thead+='<th>'+TempoUtils.locale("mine.mine_fields")+'</th>';
							for (var j=0;j<row.length;j++) {
								thead+="<th>"+row[j]+"</th>";
							}
							thead+='<th>'+TempoUtils.locale("mine.cluster_num")+'</th>';
						} else {
							tbody+='<tr><td>'+TempoUtils.locale("mine.cluster_center").replace("replace_this",i)+'</td>';
							for (var j=0;j<row.length;j++) {
								var num = Number(row[j]);
								if (!isNaN(num)){
									row[j] = TempoMineUtils.format(row[j]);
								}
								tbody+="<td>"+row[j]+"</td>";
							}
							tbody+="<td>"+classNum[i-1]+"</td>";
							tbody+='</tr>';
						}
					}
				} else {
					for (var i=0;i<centerTable.length;i++) {
						var row = centerTable[i];
						if (i == 0) {
							thead+='<th>'+TempoUtils.locale("mine.mine_fields")+'</th>';
							for (var j=0;j<row.length;j++) {
								if (j < 8 || j > colNums-9) {
									thead+="<th>"+row[j]+"</th>";
								} else if (j == 8) {
									thead+="<th>...</th>";
								}

							}
							thead+='<th>'+TempoUtils.locale("mine.cluster_num")+'</th>';
						} else {
							tbody+='<tr><td>'+TempoUtils.locale("mine.cluster_center").replace("replace_this",i)+'</td>';
							for (var j=0;j<row.length;j++) {
								if (j < 8 || j > colNums-9) {
									var num = Number(row[j]);
									if (!isNaN(num)){
										row[j] = TempoMineUtils.format(row[j]);
									}
									tbody+="<td>"+row[j]+"</td>";
								} else if (j == 8) {
									tbody+="<td>...</td>";
								}

							}
							tbody+="<td>"+classNum[i-1]+"</td>";
							tbody+='</tr>';
						}
					}
				}

				thead+='</tr></thead>';
				tbody+='</tbody>';
				$(thead).appendTo(centerTa);
				$(tbody).appendTo(centerTa);

			});
			tab.find('#tempo-mine-result-viewing-cluster-center-distance').unbind('click').bind('click',function(){
				if($(btnName)){
					$(btnName).remove();
				}
				if (!$(this).hasClass('tempo-mine-viewing-result-style-sel')) {
					$(this).addClass('tempo-mine-viewing-result-style-sel');
				}
				$(this).siblings().removeClass('tempo-mine-viewing-result-style-sel');
				clusterTableInfo.html("");
				if (distanceTable && distanceTable.length > 0) {
					var distanceTa = $('<table class="tempo-mine-insight-table"></table>').appendTo(clusterTableInfo);
					var head='<thead><tr><th>'+TempoUtils.locale("mine.center_distance")+'</td>';
					var lineData = distanceTable[0];
					var clusterNum = lineData.length;
					var showLineNum = clusterNum;
					if (clusterNum > 100) {
						showLineNum = 101;
					}
					if (clusterNum <= 17) {
						for (var i=0;i<clusterNum;i++) {
							head+='<th>'+TempoUtils.locale("mine.cluster")+(i+1)+'</th>';
						}
						head+='</tr></thead>';
						$(head).appendTo(distanceTa);
						var tbody='<tbody>';
						for (var i=0;i<showLineNum;i++) {
							var tr='<tr><td>'+TempoUtils.locale("mine.cluster")+(i+1)+'</td>';
							var row=distanceTable[i];
							for (var j=0;j<row.length;j++) {
								var num = Number(row[j]);
								if (!isNaN(num)){
									row[j] = TempoMineUtils.format(row[j]);
								}
								tr+='<td>'+row[j]+'</td>';
							}
							tr+='</tr>';
							tbody+=tr;
						}
					} else {
						for (var i = 0; i < 8; i++) {
							head+='<th>'+TempoUtils.locale("mine.cluster")+(i+1)+'</th>';
						}
						head+='<th>...</th>';
						for (var i = clusterNum-8; i < clusterNum; i++) {
							head+='<th>'+TempoUtils.locale("mine.cluster")+(i+1)+'</th>';
						}
						head+='</tr></thead>';
						$(head).appendTo(distanceTa);
						var tbody='<tbody>';
						for (var i=0;i< showLineNum;i++) {
							var row = distanceTable[i];
							if (i < 100) {
								var tr='<tr><td>'+TempoUtils.locale("mine.cluster")+(i+1)+'</td>';
								for (var j = 0; j < row.length;j++) {
									if (j < 8 || j > clusterNum-9) {
										var num = Number(row[j]);
										if (!isNaN(num)){
											row[j] = TempoMineUtils.format(row[j]);
										}
										tr+='<td>'+row[j]+'</td>';
									} else if (j == 8) {
										tr+='<td>...</td>';
									}
								}
							} else {
								var tr='<tr><td>...</td>';
								for (var j = 0; j < row.length;j++) {
									if (j < 8 || j > clusterNum-9) {
										tr+='<td>...</td>';
									} else if (j == 8) {
										tr+='<td>...</td>';
									}
								}
							}
							tr+='</tr>';
							tbody+=tr;
						}
					}
					tbody+='</tbody>';
					$(tbody).appendTo(distanceTa);
				}
			});

			tab.find('.tempo-mine-viewing-result-style:first').trigger('click');
		}

}

/**
 * 图例添加
 */
var addLegend = function(svg,labelColors,height,centerTable,classNum){
	var resultData = [];
	// 最多显示10个图例
	var maxLength = 11;
	if (centerTable.length < 11){
		maxLength = centerTable.length;
	}
	// 获取标签名称及显示名称
	for (var i=1;i<maxLength;i++){
		var item = centerTable[i];
		// 取出第二个逗号后面的所有内容
		var resItem = {};
		resItem.name = TempoUtils.locale("mine.cluster")+(i);
		resItem.index = i-1;
		resultData.push(resItem);
	}
	var legend = svg.selectAll(".legend").data(resultData)
					.enter().append("g")
					.attr("class","legend")
					.attr("tansform",function(d,i){
						return "translate(0,100)"; 
					});
	// 标签名称
	legend.append("text")
				.attr("y",function(d){return 25;})
				.attr("x",function(d,i){
					return 50+115*i+10;
				})
				.data(resultData)
				.attr("dy",".35em")
				.attr("text-anchor","start")
				.text(function(d,i){
					return d.name;
				});
	// 标签tooltip
	legend.append("title")
				.data(resultData)
				.text(function(d,i){
					return d.name;
				});
	// 标签颜色
	legend.append("circle")
				.attr("r",function(d){return 6;})
				.attr("cx",function(d,i){
					return 50+115*i;
				})
				.data(resultData)
				.attr("cy",function(d){return 25;})
				.attr("fill",function(d,i){
					return labelColors[d.index];
				});
}

/**
 * 过滤数据，最多显示10个分类数据
 * pointArr:点的集合
 * keys：分类数组
 * maxRadius:分类中的最大数量
 * type 区分单字符还是多字符  2为多字符  1为单字符
 */
var filterPointer = function (pointArr, type) {
    // 唯一分类值
    var keys = [];
    var newPointArr = [];
    var maxRadius = 0;
    //单字符时 y取pointArr[i][0]
    if (pointArr.length < 20 && "1" == type) {
        for (var i = 0; i < pointArr.length; i++) {
            keys.push(pointArr[i][0]);
        }
        return {"pointArr": pointArr, "key": keys, "maxRadius": maxRadius};
    } else if (pointArr.length < 20 && "2" == type) {
        //多字符时 y取pointArr[i][1]
        for (var i = 0; i < pointArr.length; i++) {
            keys.push(pointArr[i][1]);
        }
        return {"pointArr": pointArr, "key": keys, "maxRadius": maxRadius};
    } else if (pointArr.length >= 20 && "1" == type) {
        for (var i = 0; i < pointArr.length; i++) {
            // 若当前端点分类名称已添加，则添加该点
            if (newPointArr.indexOf(pointArr[i][0]) != -1) {
                if (TempoUtils.isInt(pointArr[i][3]) && parseInt(pointArr[i][3]) > maxRadius) {
                    maxRadius = parseInt(pointArr[i][3]);
                }
                newPointArr.push(pointArr[i]);
                continue;
            }
            // 若已超出限制，则不添加该点
            if (newPointArr.length > 20) {
                continue;
            }
            if (TempoUtils.isInt(pointArr[i][3]) && parseInt(pointArr[i][3]) > maxRadius) {
                maxRadius = parseInt(pointArr[i][3]);
            }
            newPointArr.push(pointArr[i]);
            keys.push(pointArr[i][0]);
        }
        return {"pointArr": newPointArr, "key": keys, "maxRadius": maxRadius};
    } else if (pointArr.length >= 20 && "2" == type) {
        for (var i = 0; i < pointArr.length; i++) {
            // 若当前端点分类名称已添加，则添加该点
            if (newPointArr.indexOf(pointArr[i][1]) != -1) {
                if (TempoUtils.isInt(pointArr[i][3]) && parseInt(pointArr[i][3]) > maxRadius) {
                    maxRadius = parseInt(pointArr[i][3]);
                }
                newPointArr.push(pointArr[i]);
                continue;
            }
            // 若已超出限制，则不添加该点
            if (newPointArr.length > 20) {
                continue;
            }
            if (TempoUtils.isInt(pointArr[i][3]) && parseInt(pointArr[i][3]) > maxRadius) {
                maxRadius = parseInt(pointArr[i][3]);
            }
            newPointArr.push(pointArr[i]);
            keys.push(pointArr[i][1]);
        }
        return {"pointArr": newPointArr, "key": keys, "maxRadius": maxRadius};
    }
}

/**
 * maxRadius:为最大的散点的值
 * value：为当前值
 * 获取三点半径大小，若超过最大值，则返回最大值，默认最小值为5，最大值为13
 */
var getRadius = function(maxRadius,value){
	value = parseInt(value);
	var maxValue = 13;
	var minValue = 5;
	if (!TempoUtils.isInt(value)){
		return minValue;
	}
	var percent = 0.01;
	if　(maxRadius > 0){
		percent = (maxValue-minValue)/maxRadius;
	}
	var res = value*percent + minValue;
	if (res > maxValue){
		return maxValue;
	} else {
		return res;
	}
}
